package com.swallow.cloud.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swallow.cloud.common.model.R;
import com.swallow.cloud.entity.Role;
import com.swallow.cloud.entity.User;
import com.swallow.cloud.service.MenuService;
import com.swallow.cloud.service.OfficeService;
import com.swallow.cloud.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author swallow
 * @since 2019-03-18
 */
@Controller
@RequestMapping("${adminPath}/role")
public class SysRoleController {


    @Autowired
    private RoleService roleService;

    @RequestMapping("manager")
    public String manager(){
        return "/modules/role/role";
    }

    @RequestMapping("list")
    @ResponseBody
    public Object list(Role user, Integer current, Integer size){
        IPage<Role> page=roleService.page(new Page<>(current,size),new QueryWrapper<>(user));
        return page;
    }

    @RequestMapping("roleList")
    @ResponseBody
    public Object roleList(){
        List<Role>  list=roleService.list(new QueryWrapper<>());
        return R.success(list);
    }

    @RequestMapping("info")
    @ResponseBody
    public R info(String id, HttpServletRequest request){
        Role role=roleService.getById(id);
        return R.success(role);
    }

    /**
     * 新增修改
     * @return
     */
    @RequestMapping("save")
    @ResponseBody
    public R save(Role role){
        role.insertOrUpdate();
        return R.success();
    }
    /**
     * 新增修改
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public R delete(String ... ids){
        roleService.removeByIds(Arrays.asList(ids));
        return R.success();
    }
}
